package com.example.design.singletonDemo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 反射破解单例
 */
public class ReflexSingletion {

    /**
     * 反射
     *
     * @param args
     */
    public static void main(String[] args) {
            try {
                Singleton3 singleton3 = Singleton3.getSingleton3();
                Constructor<Singleton3> singleton3Constructor = Singleton3.class.getDeclaredConstructor();
                singleton3Constructor.setAccessible(true);
                Singleton3 singleton31 = singleton3Constructor.newInstance();
                System.out.println(singleton3==singleton31);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
}
